<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function() {
	resetForm();
	
	$(document).on('click', '.line', function() {
		resetForm();
		$(this).css('background-color', 'blue').css('color', 'white');
		$('#command').val('updateLine');
		$('#line_no').val($(this).attr('name'));
		$('#line_name').val($(this).find('.line_name').text());
		$('#submitBtn').html('수정');
		$('#resetBtn').show();
		$('#delBtn').show();
	});
	
	$('#submitBtn').click(function() {
		$('#editForm').submit();
	});
	
	$('#delBtn').click(function() {
		location.href="major.do?command=deleteLine&&line_no="+$('#line_no').val();
	});
	
	$('#resetBtn').click(function() {
		resetForm();
	});
});

function resetForm() {
	$('.line').css('background-color', 'white').css('color', 'black');
	$('#command').val('registerLine');
	$('#line_no').val('0');
	$('#line_name').val('');
	$('#submitBtn').html('등록');
	$('#resetBtn').hide();
	$('#delBtn').hide();
}
</script>
</head>
<body>
<a href="index.do?command=menu">메뉴로</a>
<div id="listDiv">
	<div id="linelist">
		<c:forEach var="line" items="${requestScope.linelist}">
			<div class="line" name="${line.line_no}"><div class="line_name">${line.line_name}</div></div>
		</c:forEach>
	</div>
</div>
<div id="editDiv">
	<div id="formDiv">
		<form action="major.do" method="post" id="editForm">
			<input type="hidden" id="command" name="command" value="registerLine">
			<input type="hidden" id="line_no" name="line_no" value="0">
			계열 이름 <input id="line_name" name="line_name">
		</form>
		<div id="submitBtn">등록</div>
		<div id="delBtn">삭제</div>
		<div id="resetBtn">새 계열 등록</div>
	</div>
</div>
</body>
</html>